#include <REGX52.H>
/**
 * 按照如下顺序流动
 * 1357
 * 8642
 * 1357
 */
void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}

void main()
{
  unsigned char led = 0x01; 
    unsigned char direction = 0; // 方向标志0=左移（1→8），1=右移（8→1）

    while(1) {
        P2 = ~led; 
        delay_ms(2000);

        if (!direction) {
            led <<= 2;      
            if (led == 0x00) {
                led = 0x80; // 到最高位后切换方向
                direction = 1;
            }
        } else {
            led >>= 2;    
            if (led == 0x00) {
                led = 0x01; // 到最低位后切换方向
                direction = 0;
            }
        }
    }
}